package com.hmall.search.web;


import com.hmall.search.domain.po.ItemDoc;
import com.hmall.search.domain.query.ItemPageQuery;
import com.hmall.search.domain.vo.PageVO;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class searchController {


    @Autowired
    private SearchService searchService;

    @GetMapping("/hi")
    public String hi() {
        return "hi";
    }

    // 自动bu全
    @GetMapping("/suggestion")
    public List<String> getSuggestion(
            @RequestParam("key") String prefix
    ) {

        return searchService.getSuggestion(prefix);
    }


    // 过滤项聚合功能
    @PostMapping("/filters")
    public Map<String, List<String>> searchPost(@RequestBody ItemPageQuery query) {
        System.out.println("过滤项聚合功能\n" + query);
        return searchService.searchPost(query);
    }

    // 实现基本搜索功能
    @PostMapping("/list")
    public PageVO<ItemDoc> search(@RequestBody ItemPageQuery query) {
        return searchService.search(query);
    }


}
